# Sample Plugin: Filter
#

package MT::Plugin::MyPlugin05;

use strict;
use MT;
use MT::Template::Context;
use vars qw($VERSION);
$VERSION = '0.2';

@MT::Plugin::MyPlugin05::ISA = qw(MT::Plugin);

my $plugin = new MT::Plugin::MyPlugin05({
    name => '<MT_TRANS phrase=\'Sample Plugin: add_link filter\'>',
    version => $VERSION,
    description => '<MT_TRANS phrase=\'_PLUGIN_DESCRIPTION\'>',
    author_name => '<MT_TRANS phrase=\'_PLUGIN_AUTHOR\'>',
    author_link => 'http://www.example.com/about/',
    doc_link => 'http://www.example.com/docs/',
    l10n_class => 'MyPlugin05::L10N',
    settings => new MT::PluginSettings([
        ['add_link_target'],
        ['add_link_url'],
    ]),
    system_config_template => 'config.tmpl',
});

MT->add_plugin($plugin);

MT::Template::Context->add_global_filter(add_link => \&add_link);

sub add_link {
    my($text, $arg, $ctx) = @_;

    my $target = $plugin->get_config_value('add_link_target', 'system');
    my $url = $plugin->get_config_value('add_link_url', 'system');
    
    if($arg == '1') {
        $text =~ s!$target!<a href="$url">$target</a>!gs;
    }
    return $text;
}

1;
